#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int n = 0, p = 0;
    cin >> n >> p;
    vector<int> a(n, 0);
    for (int i = 0;i < n;i++)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int r = 0;
    int max = 0;
    for (int l = 0;l < n;l++)
    {
        while (r < n && a[r] - a[l] <= 2 * p) r++;
        //cout<<"l="<<l<<"r="<<r<<endl;
        if (r - l > max) max = r - l;
    }
    cout << max << endl;
    return 0;
}